      SUBROUTINE RDREQMT3(LUREQMT,FILENAMES,LUERR,IERR)
C
C THIS ROUTINE IS PART OF THE TOSS REQUIREMENTS FILE READER PACKAGE. IT
C READS THE REQUIREMENTS FILE TO FETCH EXPERIMENT NAMES PRESENT THERE
C AND DOES SOME ERROR CHECKS.
C
C***********************************************************************
C
C BY C PETRUZZO GSFC/742  1/86
C        MODIFIED....
C
C***********************************************************************
C
      INCLUDE 'RDREQMT.INC'
C
      CHARACTER*8 FILENAMES(MAXEXPMTS),TESTNAME,CH8NAME,
     *            NULLNAME/'NULLNAME'/
      CHARACTER*15 KWD
      LOGICAL FINI
C
C ****************
C *  INITIALIZE  *
C ****************
C
      IERR = 0
      NUMNAMES = 0
      DO IEXP=1,MAXEXPMTS
        FILENAMES(IEXP) = NULLNAME
        END DO
C
      REWIND LUREQMT
C
C
C ******************************************
C *  READ THE FILE, SAVE EXPERIMENT NAMES  *
C ******************************************
C
  200 CONTINUE
C
C SKIP THE COMMENT LINE
C
      READ(LUREQMT,2000,END=205)
C
C READ AN EXPERIMENT NAME AND SAVE IT IN FILENAMES
C
      CH8NAME = ' '
      READ(LUREQMT,*,END=210) CH8NAME
      NUMNAMES = NUMNAMES + 1
      IF(NUMNAMES.LE.MAXEXPMTS) THEN   ! MAXEXPMTS SET IN RDREQMT.INC
        FILENAMES(NUMNAMES) = CH8NAME
      ELSE
C      ERROR. MORE EXPMTS ARE ON THE FILE THAN THIS READER CAN HANDLE.
        IERR = 4
        IF(LUERR.GT.0) WRITE(LUERR,9901)
     *      'TOO MANY EXPERIMENTS ON REQUIREMENTS FILE. SEE RDREQMT3.'
        GO TO 9999
        END IF
C
C READ THE KEYWORD SUBGROUP.
C
      FINI = .FALSE.
      DO WHILE (.NOT.FINI)
        READ(LUREQMT,*,END=210) KWD,(DUM,I=1,MAXPARMS1)
        CALL MATCHCH(KWD,MAXKEYS,KEYWORD,INDEX)
        FINI = INDEX.EQ.MAXKEYS
C      VERIFY THAT KEYWORD IS VALID.
        IF(INDEX.EQ.0) THEN
          IERR = 1
          IF(LUERR.GT.0) WRITE(LUERR,9901)
     *          'INVALID KEYWORD= ' // KWD // '   EXPMT= ' // CH8NAME
          GO TO 9999
          END IF
        END DO
C
C SKIP THE TARGET-SPECIFIC RECORDS FOR THIS EXPERIMENT.
C
      FINI = .FALSE.
      DO WHILE (.NOT.FINI)
        ID = 0
        READ(LUREQMT,*,END=210) ID,(DUM,I=1,MAXPARMS2)
        FINI = ID.EQ.-9999
        END DO
C
C END-DATA FOR THE CURRENT EXPERIMENT.  GET THE NEXT EXPERIMENT NAME.
C
      GO TO 200
C
C
  205 CONTINUE
C
C ********************************
C *  VERIFY EXPERIMENT NAMES OK  *
C ********************************
C
C VERIFY THAT THE FILE CONTAINS AT LEAST ONE EXPERIMENT, NO BLANK
C NAMES, AND NO DUPLICATE NAMES.
C
C    VERIFY ONE OR MORE EXPERIMENTS PRESENT.
      IF(NUMNAMES.EQ.0) THEN
        IERR = 1
        IF(LUERR.GT.0) WRITE(LUERR,9901)
     *          'REQUIREMENTS FILE HAS NO EXPERIMENTS(EMPTY FILE?).'
        GO TO 9999
        END IF
C
C    VERIFY REQUIREMENTS FILE HAS NO BLANK NAMES.
      DO INAME=1,NUMNAMES
        IF(FILENAMES(INAME).EQ.' ') THEN
          IERR = 1
          IF(LUERR.GT.0) WRITE(LUERR,9901)
     *          'REQUIREMENTS FILE HAS A BLANK/MISSING EXPERIMENT NAME.'
          GO TO 9999
          END IF
        END DO
C
C    VERIFY REQUIREMENTS FILE HAS NO DUPLICATE NAMES.
      DO INAME=1,NUMNAMES
        DO JNAME=INAME,NUMNAMES
          IF(INAME.NE.JNAME .AND.
     *          FILENAMES(INAME).EQ.FILENAMES(JNAME)) THEN
            IERR = 1
            IF(LUERR.GT.0) WRITE(LUERR,9901)
     *          'REQUIREMENTS FILE HAS DUPLICATE EXPERIMENT NAME.' //
     *           ' NAME= ' // FILENAMES(INAME)
            GO TO 9999
            END IF
          END DO
        END DO
C
      GO TO 9999
C
C
C ************************
C *  PREMATURE END-FILE  *
C ************************
C
C END-FILE IN THE KEYWORD OR TARGET SUBGROUPS GOT US HERE.
C
  210 CONTINUE
      IERR = 1
      IF(LUERR.GT.0) WRITE(LUERR,9901)
     *     'ON REQMTS FILE, FINAL EXPERIMENT IS INCOMPLETE.'
      GO TO 9999
C
C
 9999 CONTINUE
C
C *************
C *  WRAP UP  *
C *************
C
      DO I=1,MAXEXPMTS
        IF(FILENAMES(I).EQ.NULLNAME) FILENAMES(I) = ' '
        END DO
C
      RETURN
C
 2000 FORMAT(A)
 9901 FORMAT(/,
     *   ' OBSERVATION REQUIREMENTS FILE READER. ERROR CONDITION.'/,
     *   (5X,A))    ! ERROR MESSAGE TEXT
      END
